feat(sheets): add +undo shortcut for AI-tool edits#1321
Open
zhengzhijiej-tech wants to merge 5 commits into
Open
feat(sheets): add +undo shortcut for AI-tool edits#1321zhengzhijiej-tech wants to merge 5 commits into
zhengzhijiej-tech wants to merge 5 commits into
Conversation
Add a token-scoped +undo shortcut that reverses recent sheet edits made through the sheet-ai write tools, by invoking the undo_last write tool. - +undo [--steps N | --op NAME]: undo the last N steps, or a named op - thread a session-stable transaction id (LARK_CLI_SHEET_TRANSACTION_ID) into the tool request's extra.transaction_id, so a group of edits and a later +undo share one server-side undo stack; omitted when unset to preserve per-request behavior - flag-defs + generated defs for the new shortcut
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
buildToolBody attached extra.transaction_id to every tool invocation, including read tools (get_cell_ranges, get_range_as_csv, search_data, get_workbook_structure, ...). A read scoped to a transaction id resolves against that transaction's snapshot instead of the live document, so reads returned blank cells whenever LARK_CLI_SHEET_TRANSACTION_ID was set. Gate the extra block to ToolKindWrite — the undo stack only ever concerns writes — by threading kind into buildToolBody at every call site. Adds a regression test that read tools omit the transaction id.
+recover --to-revision N rolls the whole spreadsheet back to a past revision via the recover_to_revision write tool (facade reuses its existing ProcessRecoverCs / revert-by-revision path). Distinct from +undo, which is precise and this-link-only; +recover is a full-document restore that discards all later edits, so it carries no sheet selector and a prominent overwrite warning in --help. Adds the +recover flag-defs entry (url / spreadsheet-token / to-revision) to both data/flag-defs.json and the compiled flag_defs_gen.go.
Without LARK_CLI_SHEET_TRANSACTION_ID set, every CLI write received a fresh
server-minted transaction id, so a group of edits and a later +undo never
shared an undo stack and +undo could not reach the prior writes.
Resolve the write tool's extra.transaction_id in three tiers:
1. $LARK_CLI_SHEET_TRANSACTION_ID — explicit caller override.
2. else a value derived from the OS session (getsid on unix, falling back
to the parent pid; salted with uid and boot/host) so edits in one shell
session group by default, with no env var to set. Each invocation is a
fresh process and recomputes the same id rather than persisting one.
3. else "" — the server mints a per-request id as before.
The derivation never needs the spreadsheet token (undo read-back is already
keyed by token + transaction id), so buildToolBody keeps its signature and
reads still never carry the id.
The stdlib syscall package exposes Getsid on darwin/BSD but not on linux, so the session-id derivation broke linux cross-compilation. Switch to golang.org/x/sys/unix.Getsid (already a direct dependency), and narrow the build tag from !windows to unix to match where that package is available. Verified all six release targets (darwin/linux/windows x amd64/arm64) build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add a token-scoped
+undoshortcut that reverses recent sheet edits made through the sheet-ai write tools, by invoking theundo_lastwrite tool.+undo [--steps N | --op NAME]: undo the last N steps, or a named operationLARK_CLI_SHEET_TRANSACTION_ID) into the tool request'sextra.transaction_id, so a group of edits and a later+undoshare one server-side undo stack; omitted when unset to preserve per-request behaviorWhy
Lets an agent driving lark-cli undo a group of AI-tool sheet edits in one call, rather than manually reconstructing prior state.
Notes
Depends on the backend
undo_lastwrite tool (byted-sheet) + facade registration (sheet-facade-agg). The backend reverse-changeset path is still being finalized; the CLI side here is self-contained and gated by the transaction-id env var.